package cn.ysbd.datafactory.config;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.time.Duration;

/**
 * @Author: YinHeng
 * @Description:
 * @DateTime: 2022/8/31 17:00
 */
public class JedisPoolFactory {

    private static JedisPool JEDIS_POOL;

    private static JedisPool initJedisPool() {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(400);
        config.setMaxIdle(40);
        config.setMaxWait(Duration.ofSeconds(600));
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
        return new JedisPool(config, "10.52.1.184", 6379,1800,"pY8HlZ1wXE5av");
    }

    public static Jedis getJedis() {
        if (JEDIS_POOL == null) {
            JEDIS_POOL = initJedisPool();
        }
        return JEDIS_POOL.getResource();
    }
}
